<template>
	<view>
		<view class="logo-container d-flex a-center j-center">
			<image src="../../../static/images/logo1.png" style="height: 112upx;width: 390upx;" mode=""></image>
		</view>
		<view class="register-form">
			<view class="sun-form-item border-bottom">
				<text class="sun-label">密码</text>
				<input v-model="infoData.password" type="password">
			</view>
			<view class="sun-form-item border-bottom">
				<text class="sun-label">确认密码</text>
				<input v-model="infoData.passwordConfirm" type="password">
			</view>
			<view class="sun-btn" @tap="toLoginPage">
				<text class="font-30">确认</text>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/common/lib/request.js';
	export default {
		data() {
			return {
				captcha: '',
				mobile:'',
				infoData: {
					password: "",
					passwordConfirm: ""
				}
			}
		},
		onLoad(option) {
			let captcha = option.captcha;
			if (captcha) {
				this.captcha = captcha;
				this.mobile = option.mobile;
			}
		},
		methods: {
			toLoginPage() {
				if (this.infoData.password.trim() != this.infoData.passwordConfirm) {
					uni.showToast({
						title: '两个密码不一致！'
					});
					return
				}
				const _this = this;
				
					api.request({
							url: '/resetPassword',
							method: 'POST',
							data: {
								newPassword: _this.infoData.password,
								mobile: _this.mobile,
								captcha: _this.captcha
							}
						})
						.then(response => {
							console.log(response);
							uni.removeStorageSync('token')
							uni.removeStorageSync('userInfo')
							uni.redirectTo({
								url: '/pages/mine/login/login'
							})
						})
						.catch(err => {
							console.log(err);
						});
				}

		}
	}
</script>

<style scoped>
	.logo-container {
		width: 100%;
		height: 375rpx;
	}

	.register-form {
		width: 570upx;
		padding: 30upx 90upx;
	}

	.sun-form-item {
		display: flex;
		margin-bottom: 20upx;
		height: 80upx;
		align-items: center;
	}

	.sun-form-item .sun-label {
		width: 120upx;
	}

	.sun-form-item input {
		flex: 1;
		font-size: 28upx;
	}

	.sun-btn {
		margin-top: 80upx;
		background-color: #005BAC;
		height: 90upx;
		color: white;
		text-align: center;
		line-height: 90upx;
	}
</style>
